'''
Created on 2014. 4. 3.

@author: Administrator
'''
import win32com.client
from InGA.environment import *

class MEnvironment(Environment):
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
        self.cpBuyingData = win32com.client.Dispatch("CpTrade.CpTdNew5331A")
        
        Environment.__init__(self)
        #환경 Property 초기화
        self.setProperties("Total Money", 0)
    
    def setAccount(self, accountNumber, conn):
        if conn == True :
            print(type(accountNumber))
            self.cpBuyingData.SetInputValue(0, accountNumber)
            self.cpBuyingData.BlockRequest()          
        else :
            print("CP 연결 오류")
        
    def getAvailableMoney(self, conn):
        if conn == True :            
            self.setProperties("Available Money", self.cpBuyingData.GetHeaderValue(47))            
            return self.properties["Available Money"]
        else :
            print("CP 연결 오류")
            return 0
        
        
    def evaluateTotalMoney(self):
        #TODO
        ##현재 계좌의 전체 가치 평가
        print("구현중")
        
    def getTotalMoney(self):
        return self.properties["Total Money"]